package com.github.baichuan.iot.protocol.codec;

import org.apache.commons.codec.binary.Hex;

/**
 * 报文消息异常
 */
public class MessageException extends RuntimeException {
    private byte[] bytes;

    public MessageException(String message){
        super(message);
    }

    public MessageException(String message, byte[] bytes){
        super(message);
        this.bytes = bytes;
    }

    @Override
    public String toString(){
        StringBuilder builder = new StringBuilder();
        builder.append(getMessage());
        if(bytes != null && bytes.length > 0){
            builder.append(":");
            builder.append(Hex.encodeHexString(bytes));
        }
        return builder.toString();
    }
}
